using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
{
class MainShip : Ship
{
-
- uint Multiplier;
- uint Lives;
- uint Score;
+
+ public static Color BlueColor;
+ public static Color RedColor;
+
ParticleEngine particleEngine;
- public MainShip(Game newGame) : base(newGame) {}
+ protected bool Shooting;
+ protected int ShotCooldown;
+
+ protected float CurrentImmortalTime;
+ protected float MaxImmortalTime;
+ protected bool Flashing;
+
+ public MainShip(SuperPolarity newGame) : base(newGame) {}
+
+ ~MainShip()
+ {
+ particleEngine = null;
+ }
public override void Initialize(Texture2D texture, Vector2 position)
{
base.Initialize(texture, position);
+ MainShip.BlueColor = new Color(230, 244, 249);
+ MainShip.RedColor = new Color(255, 234, 241);
+
InitParticleEngine();
SetPolarity(Polarity.Positive);
- Multiplier = 1;
- Lives = 3;
- Score = 0;
+ ShotCooldown = 50;
+ MaxImmortalTime = 1500;
+
+ BoxDimensions.X = 2;
+ BoxDimensions.Y = 2;
+ BoxDimensions.W = 2;
+ BoxDimensions.Z = 2;
+ InitBox();
BindInput();
}
void InitParticleEngine()
{
- List<Texture2D> texturesList = new List<Texture2D>();
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\circle"));
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\diamond"));
- texturesList.Add(game.Content.Load<Texture2D>("Graphics\\star"));
-
- particleEngine = new ParticleEngine(texturesList, Position);
+ particleEngine = ParticleEffectFactory.CreatePolarCircle(Position);
}
void BindInput()
InputController.Bind("moveX", HandleHorizontalMovement);
InputController.Bind("moveY", HandleVerticalMovement);
InputController.Bind("changePolarity", HandleChangePolarity);
+ InputController.Bind("shoot", HandleShot);
+ }
+
+ protected void HandleShot(float value)
+ {
+ var bullet = ActorFactory.CreateBullet(Position, Angle);
+
+ Children.Add(bullet);
+ bullet.Parent = this;
+
+ Shooting = true;
+ Timer t = new Timer(new TimerCallback(UnlockShot));
+ t.Change(ShotCooldown, Timeout.Infinite);
+ }
+
+ protected void UnlockShot(object state)
+ {
+ InputController.Unlock("shoot");
}
protected void HandleChangePolarity(float value)
{
base.SwitchPolarity();
SwitchParticleEngine(CurrentPolarity);
+ game.Player.ResetMultiplier();
}
public override void SetPolarity(Polarity newPolarity)
{
if (polarity == Polarity.Positive)
{
- particleEngine.Color = Color.Red;
+ particleEngine.Color = MainShip.RedColor;
}
else if (polarity == Polarity.Negative)
{
- particleEngine.Color = Color.Blue;
+ particleEngine.Color = MainShip.BlueColor;
}
else
{
particleEngine.EmitterLocation = Position;
particleEngine.Update();
ConstrainToEdges();
+ UpdateImmortality(gameTime);
+ Shooting = false;
+ }
+
+ public void UpdateImmortality(GameTime gameTime)
+ {
+ if (Immortal)
+ {
+ CurrentImmortalTime += gameTime.ElapsedGameTime.Milliseconds;
+
+ if (Flashing)
+ {
+ Color = new Color(255, 255, 255, 128);
+ }
+ else
+ {
+ Color = Color.White;
+ }
+
+ Flashing = !Flashing;
+
+ if (CurrentImmortalTime > MaxImmortalTime)
+ {
+ Immortal = false;
+ Color = Color.White;
+ }
+ }
+ }
+
+ public override void Move(GameTime gameTime)
+ {
+ base.Move(gameTime);
+
+ if (Shooting)
+ {
+ if (Velocity.X > ActVelocity)
+ {
+ Velocity.X = ActVelocity;
+ }
+
+ if (Velocity.X < -ActVelocity)
+ {
+ Velocity.X = -ActVelocity;
+ }
+
+ if (Velocity.Y > ActVelocity)
+ {
+ Velocity.Y = ActVelocity;
+ }
+
+ if (Velocity.Y < -ActVelocity)
+ {
+ Velocity.Y = -ActVelocity;
+ }
+ }
}
public override void Magnetize(Ship ship, float distance, float angle)
particleEngine.Draw(spriteBatch);
base.Draw(spriteBatch);
}
+
+ public override void Collide(Actor other, Rectangle collision)
+ {
+ if (other.GetType().IsAssignableFrom(typeof(StandardShip)) &&
+ !Immortal)
+ {
+ Die();
+ }
+ }
+
+ protected override void Die()
+ {
+ game.Player.Lives = game.Player.Lives - 1;
+ game.Player.ResetMultiplier();
+ if (game.Player.Lives < 0)
+ {
+ Dying = true;
+ }
+ else {
+ Immortal = true;
+ CurrentImmortalTime = 0;
+ }
+ }
}
}